package com.wlb.es.controller;

import com.wlb.es.entity.User;
import com.wlb.es.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
public class UserController {
    @Autowired
    UserService userService;

    /**
     * 添加用户
     */
    @GetMapping("add")
    public String add(){
        userService.add();
        return "添加成功";
    }

    /**
     * 查询一个user
     */
    @GetMapping("find/{id}")
    public List<User> findById(@PathVariable String id){
        return userService.findById(id);
    }

    /**
     * 查询所有用户
     */
    @GetMapping("findAll")
    public List<User> findAll(){
        return userService.findAll();
    }

    /**
     * 删除用户
     */
    @GetMapping("delete/{id}")
    public String deleteById(@PathVariable String id){
        userService.deleteById(id);
        return "删除成功";
    }

    /**
     * 修改用户
     */
    @GetMapping("update")
    public String update(){
        userService.update();
        return "更新成功";
    }

}
